package com.sanshi.project.assets.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sanshi.project.admin.api.entity.PrintTemplateEntity;
import com.sanshi.project.assets.mapper.PrintItemMapper;
import com.sanshi.project.assets.mapper.PrintTemplateMapper;
import com.sanshi.project.assets.service.PrintTemplateService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 打印模版配置表
 *
 * @author nikon
 * @date 2023-11-16 16:22:01
 */
@Service
@RequiredArgsConstructor
public class PrintTemplateServiceImpl extends ServiceImpl<PrintTemplateMapper, PrintTemplateEntity> implements PrintTemplateService {
    private final PrintItemMapper printItemMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveDeep(PrintTemplateEntity printTemplate) {
        baseMapper.insert(printTemplate);
        return Boolean.TRUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateDeep(PrintTemplateEntity printTemplate) {
        baseMapper.updateById(printTemplate);
        return Boolean.TRUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean removeDeep(Long[] ids) {
        baseMapper.deleteBatchIds(CollUtil.toList(ids));
        return Boolean.TRUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean removeChild(Long[] ids) {
        printItemMapper.deleteBatchIds(CollUtil.toList(ids));
        return Boolean.TRUE;
    }
}